VERSION 5.00
Begin VB.Form frmAdoLogon 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "Database Logon"
   ClientHeight    =   4455
   ClientLeft      =   45
   ClientTop       =   360
   ClientWidth     =   3870
   Icon            =   "frmAdoLogon.frx":0000
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   4455
   ScaleWidth      =   3870
   StartUpPosition =   2  'CenterScreen
   Begin VB.Frame Frame1 
      Height          =   3612
      Left            =   120
      TabIndex        =   8
      Top             =   120
      Width           =   3612
      Begin VB.Frame fraParams 
         Caption         =   "Database Parameters"
         Height          =   2172
         Left            =   120
         TabIndex        =   9
         Top             =   1200
         Width           =   3372
         Begin VB.TextBox txtUID 
            Height          =   288
            Left            =   1200
            TabIndex        =   2
            Top             =   360
            Width           =   1812
         End
         Begin VB.TextBox txtPassword 
            Height          =   288
            IMEMode         =   3  'DISABLE
            Left            =   1200
            PasswordChar    =   "*"
            TabIndex        =   3
            Top             =   756
            Width           =   1812
         End
         Begin VB.TextBox txtDsn 
            Height          =   288
            Left            =   1200
            TabIndex        =   4
            Top             =   1164
            Width           =   1812
         End
         Begin VB.TextBox txtDatabase 
            Height          =   288
            Left            =   1200
            TabIndex        =   5
            Top             =   1560
            Width           =   1812
         End
         Begin VB.Label lblDatabase 
            Caption         =   "Database:"
            Height          =   252
            Left            =   120
            TabIndex        =   13
            Top             =   1680
            Width           =   852
         End
         Begin VB.Label lblDSN 
            Caption         =   "DSN:"
            Height          =   252
            Left            =   120
            TabIndex        =   12
            Top             =   1236
            Width           =   972
         End
         Begin VB.Label lblPWD 
            Caption         =   "Password"
            Height          =   252
            Left            =   120
            TabIndex        =   11
            Top             =   804
            Width           =   852
         End
         Begin VB.Label lblUid 
            Caption         =   "User Name:"
            Height          =   252
            Left            =   120
            TabIndex        =   10
            Top             =   360
            Width           =   1092
         End
      End
      Begin VB.Frame fraDbType 
         Caption         =   "Database Type"
         Height          =   732
         Left            =   120
         TabIndex        =   14
         Top             =   240
         Width           =   3372
         Begin VB.OptionButton optOracle 
            Caption         =   "Oracle"
            Height          =   252
            Left            =   2040
            TabIndex        =   1
            Top             =   360
            Width           =   972
         End
         Begin VB.OptionButton optSql 
            Caption         =   "Sql Server"
            Height          =   252
            Left            =   240
            TabIndex        =   0
            Top             =   360
            Width           =   1332
         End
      End
   End
   Begin VB.CommandButton cmdLogon 
      Caption         =   "&Logon"
      Default         =   -1  'True
      Height          =   495
      Left            =   1080
      TabIndex        =   6
      Top             =   3840
      Width           =   1215
   End
   Begin VB.CommandButton cmdCancel 
      Cancel          =   -1  'True
      Caption         =   "&Cancel"
      Height          =   495
      Left            =   2400
      TabIndex        =   7
      Top             =   3840
      Width           =   1215
   End
End
Attribute VB_Name = "frmAdoLogon"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Public blnCancelled As Boolean

Private strDbType As String

Private Sub cmdOK_Click()
    
    Unload Me

End Sub
Private Sub cmdCancel_Click()

    'change to sql server
    blnCancelled = True
    
    Unload frmAdoLogon
End Sub

Private Sub cmdLogon_Click()

    Static i As Integer
    Dim strConStr As String
    Dim blnSuccess As Boolean
    
    If fraParams.Enabled = False Then
        MsgBox "Please select a database type."
        Exit Sub
    Else
        If optSql.Value = True Then
            strDbType = SQL_DB
        Else
            strDbType = ORA_DB
        End If
    End If
    
    'check for empty fields
    If txtUID.Text = "" Then
        MsgBox "Please enter a user ID", vbOKOnly + vbExclamation
        Exit Sub
    End If
    
    If txtPassword.Text = "" Then
    '    password can be blank (only way to get into sql server=sa,,mssc05)
    '    MsgBox "Please enter a password", vbOKOnly + vbExclamation
    '    Exit Sub
    End If
    
    If txtDsn.Text = "" Then
        MsgBox "Please enter a DSN", vbOKOnly + vbExclamation
        Exit Sub
    End If
    
    'the person has tried 3 times to logon, and get it wrong 3 times so kick him out!
    If i >= 3 Then
        MsgBox "Too many logon attemps, shutting down.", vbOKOnly + vbCritical, "Logon"
        blnCancelled = False
        Unload frmAdoLogon
    Else
    
     'change to sql server
        
        
        strConStr = "Provider=" & strDbType & _
                    ";Data Source=" & txtDsn.Text & _
                    ";User ID=" & txtUID.Text & _
                    ";Password=" & txtPassword.Text & _
                    ";Initial Catalog=" & txtDatabase.Text & _
                    ";Persist Security Info=False"
        '"Provider=SQLOLEDB.1;Data Source=MSSC05;User ID=sa;Password=;Initial Catalog=pgiz;Persist Security Info=False"
        
        'barb: put this back when encrypt is fixed
        'objReg.AdoConnectString = Encrypt(strConStr, "richardknowles")
        objReg.AdoConnectString = strConStr
        
    blnCancelled = False
    
    Unload frmAdoLogon
    
    '
    'blncode = Globals.DBserver.InitConnect(UCase(txtDNS.Text), UCase(txtUID.Text), UCase(txtPassword.Text))
    'If Not blncode Then
'    If Not blnSuccess Then
'        i = i + 1
'        MsgBox "Could not establish a connection to the database, please check your password.", vbOKOnly + vbExclamation, "Logon"
'    Else
'        Unload frmadologon
'        DoEvents
'    End If
    End If
End Sub
Private Sub DisableParams()

    fraParams.Enabled = False
    txtUID.Enabled = False
    txtPassword.Enabled = False
    txtDsn.Enabled = False
    txtDatabase.Enabled = False
    lblUid.Enabled = False
    lblPWD.Enabled = False
    lblDSN.Enabled = False
    lblDatabase.Enabled = False


End Sub

Private Sub EnableParams()

    fraParams.Enabled = True
    txtUID.Enabled = True
    txtPassword.Enabled = True
    txtDsn.Enabled = True
    txtDatabase.Enabled = True
    lblUid.Enabled = True
    lblPWD.Enabled = True
    lblDSN.Enabled = True
    lblDatabase.Enabled = True
    
    'txtUID.SetFocus

End Sub

Private Sub pctLogon_GotFocus()
    txtPassword.SetFocus
End Sub

Private Sub Form_Activate()
    Screen.MousePointer = vbDefault
End Sub

Private Sub Form_Load()
    DisplayCurrentConnectString
    
'    Me.txtUID = "KeyTax"
'    Me.txtPassword = "mindkey"
'    Me.txtDsn = "BARBARA"
'    Me.txtDatabase = "KeyTax"
    
    '"Provider=SQLOLEDB.1;
    'Data Source=MSSC05;
    'User ID=sa;
    'Password=;Initial Catalog=pgiz;
    'Persist Security Info=False"
    
    
    
End Sub

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    Screen.MousePointer = vbHourglass
End Sub

Private Sub optOracle_Click()
    optSql.Value = False
    EnableParams
    lblDatabase.Enabled = False
    Me.txtDatabase.Enabled = False
End Sub

Private Sub optSql_Click()
    optOracle.Value = False
    EnableParams
    lblDatabase.Enabled = True
    Me.txtDatabase.Enabled = True
End Sub
Public Sub DisplayCurrentConnectString()

Dim Pos As Integer
Dim strCon As String
Dim vResult() As Variant
Dim i As Integer
'barb: put this back when encrypt is fixed
'strCon = Encrypt(objReg.AdoConnectString, "richardknowles")
strCon = objReg.AdoConnectString
If strCon <> "" Then
        TokenizeString strCon, ";", vResult
        strDbType = Right(vResult(0), Len(vResult(0)) - InStr(1, vResult(0), "="))
        Select Case strDbType
            Case ORA_DB
                optOracle.Value = True
            Case SQL_DB
                optSql.Value = True
                txtDatabase.Text = Right(vResult(4), Len(vResult(4)) - InStr(1, vResult(4), "="))
            Case Else
                optOracle.Value = False
                optSql.Value = False
                DisableParams
        End Select
        txtDsn.Text = Right(vResult(1), Len(vResult(1)) - InStr(1, vResult(1), "="))
        txtUID.Text = Right(vResult(2), Len(vResult(2)) - InStr(1, vResult(2), "="))
        txtPassword.Text = Right(vResult(3), Len(vResult(3)) - InStr(1, vResult(3), "="))
Else
    optOracle.Value = False
    optSql.Value = False
    DisableParams
End If


End Sub


Private Sub txtDatabase_GotFocus()
    txtDatabase.SelStart = 0
    txtDatabase.SelLength = Len(txtDatabase.Text)
End Sub

Private Sub txtDsn_GotFocus()
    txtDsn.SelStart = 0
    txtDsn.SelLength = Len(txtDsn.Text)
End Sub

Private Sub txtPassword_GotFocus()
    txtPassword.SelStart = 0
    txtPassword.SelLength = Len(txtPassword.Text)
End Sub

Private Sub txtUID_GotFocus()
    txtUID.SelStart = 0
    txtUID.SelLength = Len(txtUID.Text)
End Sub
